package com.interview.utils;


import java.util.Calendar;
import java.util.Random;

// 测试 生成  10万个id  1秒 ~ 10秒 以内跟具机器的性能而不同   我的8g内存 4核 8线程 电脑 最高速度是1.3秒       大概每天100万个id保证不会重复
//

public class Id_Builder {



    public static String nextId(){
        char[] ch={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
        char[] Ch={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
        Calendar cal = Calendar.getInstance();
        Random sun=new Random();
        int num1=sun.nextInt(1000);//0-1000随机数
        StringBuilder time=new StringBuilder();
        time.append(num1+"-");//随机数
        time.append(cal.get(Calendar.YEAR)); //年
        time.append(ch[sun.nextInt(ch.length)]);
        time.append(Ch[sun.nextInt(ch.length)]);
        time.append(cal.get(Calendar.MONTH) + 1);//月
        time.append(ch[sun.nextInt(ch.length)]);
        time.append(Ch[sun.nextInt(ch.length)]);
        time.append(cal.get(Calendar.DAY_OF_MONTH));//日
        time.append(ch[sun.nextInt(ch.length)]);
        time.append(Ch[sun.nextInt(ch.length)]);
        time.append(cal.get(Calendar.HOUR_OF_DAY));//时
        time.append(ch[sun.nextInt(ch.length)]);
        time.append(Ch[sun.nextInt(ch.length)]);
        time.append(cal.get(Calendar.MINUTE));//分
        time.append(ch[sun.nextInt(ch.length)]);
        time.append(Ch[sun.nextInt(ch.length)]);
        time.append(cal.get(Calendar.SECOND));//秒
        time.append(ch[sun.nextInt(ch.length)]);
        time.append(cal.get(Calendar.MILLISECOND));//毫秒秒
        time.append(Ch[sun.nextInt(ch.length)]+"-");
        int num=sun.nextInt(1000);//0-1000随机数
        time.append(num);//随机数
        return time.toString();
    }


}
